<?php


/**
 * Description of GridController
 *
 * @author robert
 */
class GridController extends Zend_Controller_Action{
    public function indexAction(){
        
    }
    public function listAction(){
    # rendering view is also not necessary
    $this->_helper->viewRenderer->setNoRender();
    $this->_helper->getHelper('layout')->disableLayout();

    $req = $this->getRequest();

    # Pagination parameters
    $currentPage    = $req->getPost('page', 1);
    $resultsPerPage = $req->getPost('rp', 10);

    # Sorting parameters
    $orderBy    = $req->getPost('sortname', 'u.login_name');
    $orderType  = $req->getPost('sortorder', 'ASC');

    # Query parameters - for Searching
    $query          = $req->getPost('query', '');
    $qtype          = $req->getPost('qtype', 'u.login_name');
    #create array with paramerts to pass it to the pager
    $param=array('qtype'=> $qtype,'orderBy'=>$orderBy,'orderType'=>$orderType,
        '$query'=>$query,'currentPage'=>$currentPage,'resultsPerPage '=>$resultsPerPage);

    # Creating Doctine pager object

    $pager= TblUserTable::createPager($param);
    $items=$pager->execute();
    $numResults=$pager->getNumResults();
    $elements = array();
    # We also have to format our data array that flexifrid could retrieve it
    foreach($items as $item){
        $temp=array();
        $temp[]=$item->id;
        $temp[]=$item->email;
        $temp[]=$item->login_name;
        $temp[]=$item->status;
        $temp[] = $item->role_name;
        $temp[]="<input type='button' value='Edit' onClick="."location.href='/admin/edit?id=".base64_encode($item->id)."'"." class='edit'>";
//        print_r($temp);
        $elements[] = array(
          'id'  =>   $item->id,
          'cell'    =>   array_values($temp)
        );
//        print_r($elements);
    }
        echo Zend_Json::encode(array(
        'page'  =>   $currentPage,
        'total' =>   $numResults,
        'rows'  =>   $elements
    ));


    }

}
